//
//  NewConnections.h
//  SolarSeek
//
//  Created by Erick Fejta on 05/05/26.
//  Copyright 2005 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "Message.h"
@class NetSocket;

#ifdef _SOLARSEEK_NEW_


@interface NewConnection : NSObject {
	NetSocket *_socket;
	BOOL _connected;
	NSString *_addressLocal;
	NSString *_addressRemote;
	UInt16 _portLocal;
	UInt16 _portRemote;
	
	unsigned _speedUpCeiling;
	unsigned _speedDownCeiling;
	unsigned _speedUpCurrent;
	unsigned _speedDownCurrent;
	
	NSTimeInterval _timeIntervalTimeout;
	NSDate *_activityLast;
	
	NSMutableArray *_speedsDown;
	NSMutableArray *_speedsUp;
	unsigned _countTransferredUpLast;
	unsigned _countTransferredDownLast;
	
	id	_handler;
}

- (id)handler;
- (void)setHandler;

- (BOOL)isConnected;
- (NSString *)addressLocal;
- (NSString *)addressRemote;
- (UInt16)portLocal;
- (UInt16)portRemote;
- (unsigned)countBytesAvailable;
- (unsigned)countBytesSending;

- (unsigned)speedUpCeiling;
- (unsigned)speedDownCeiling;
- (unsigned)speedUpCurrent;
- (unsigned)speedDownCurrent;

- (NSTimeInterval)timeIntervalTimeout;

- (void)setSpeedUpCeiling:(unsigned)bytespersecond;
- (void)setSpeedDownCeiling:(unsigned)bps;

- (void)setTimeIntervalTimeout:(NSTimeInterval)timeout;

- (void)connectToSocket:(NetSocket *)socket;
- (BOOL)connectToHost:(NSString *)address onPort:(UInt16)port;
- (void)disconnect;

- (void)sendMessage:(Message *)message;
- (Message *)readMessageData:(unsigned)countBytes;
- (unsigned)readMessageLength;
- (void)sendData:(NSData *)data;
- (NSData *)readData:(unsigned)countBytes;


+ (void)setDefaultTimeIntervalTimeout:(NSTimeInterval)timeout;
+ (void)setDefaultSpeedUpCeiling:(unsigned)bps;
+ (void)setDefaultSpeedDownCeiling:(unsigned)bps;
@end

#endif